import App from './App'
import * as Pinia from 'pinia';
import uviewPlus, { setConfig } from '@/uni_modules/uview-plus'
import goToPage from '@/utils/goToPage.js'

// #ifndef VUE3
import Vue from 'vue'
import { createI18n } from 'vue-i18n'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	app.use(Pinia.createPinia());
	app.use(uviewPlus, () => {
		return {
			options: {
				// 修改config对象的属性
				config: {
					// 只加载一次字体图标
					loadFontOnce: true,
					// 修改默认单位为rpx，相当于执行 uni.$u.config.unit = 'rpx'
					unit: 'rpx'
				}
			}
		}
	})

	// 全局方法挂载
	app.config.globalProperties.goToPage = goToPage;
	app.config.globalProperties.navBack = function () {
		try {
			// 先尝试返回
			uni.navigateBack({
				fail: () => {
					// 返回失败时跳转到首页
					uni.switchTab({
						url: '/pages/index/index'
					});
				}
			});
		} catch (e) {
			// 捕获异常时也跳转到首页
			uni.switchTab({
				url: '/pages/index/index'
			});
		}
	}

	return {
		app,
		Pinia, // 此处必须将 Pinia 返回
	}
}
// #endif